using System;
using System.Diagnostics;

public class Node<T> { 
    public Node<T> Next { get; set; }
    public T Data { get; set; }

    public Node(T t)
    {
        Next = null;
        Data = t;
    }
}

public class GenericList<T> {
    private Node<T> head;
    private Node<T> tail;

    public GenericList()
    {
        tail = head = null;
    }

    public Node<T> Head
    {
        get=> head;
    }
    public void Add(T t)
    {
        Node<T> n = new Node<T>(t);
        if (tail == null){
            head = tail = n;
        }else
        {
            tail.Next = n;
            tail = n;
        }
    }

    public void ForEach() {
        Node<T> p = head;
        while (p != null)
        {
            Console.WriteLine(p.Data);
            p = p.Next;
        }
    }
}



public class ConsoleApp1
{
    public static void Main(string[] args)
    {
        Random rnd = new Random();
        GenericList<int> list = new GenericList<int>();
        for(int i = 0; i < 10; i++) {

            int num = rnd.Next(1000);
            list.Add(num);
        }

        list.ForEach();

        Action<Node<int>> action = delegate (Node<int> node)
        {
            int max = -10000;
            while(node != null)
            {
                max=Math.Max(max, node.Data);
                node = node.Next;
            }

            Console.WriteLine("最大值：" + max + "\n");
        };

        Action<Node<int>> action1 = delegate (Node<int> node)
        {
            int min = 10000;
            while (node != null)
            {
                min = Math.Min(min, node.Data);
                node = node.Next;
            }
            Console.WriteLine("最小值：" + min + "\n");
        };

        Action<Node<int>> action2 = delegate (Node<int> node)
        {
            int sum = 0;
            while (node != null)
            {
                sum += node.Data;
                node = node.Next;
            }
            Console.WriteLine("和：" + sum + "\n");
        };
        action += action1;
        action += action2;
        action(list.Head);

    }
}
